package flowWIndow.f2;

public class test1456 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        String s = "abciiidef";
        int k = 3;
        int max = solution.maxVowels(s, k);
        System.out.println(max);
    }
}
class Solution {
    public int maxVowels(String s, int k) {
        int max = 0;
        int nums = 0;
        //int vowelsMask = (1) | (1 << ('e' - 'a')) | (1 << ('i' - 'a')) | (1 << ('o' - 'a')) | (1 << ('u' - 'a'));

        for (int i = 0; i < k; i++) {
            if (isVowel(s.charAt(i))) {
                nums++;
            }
        }
        max = nums;

        for (int i = k; i < s.length(); i++) {
            if (isVowel(s.charAt(i - k))) {
                nums--;
            }
            if (isVowel(s.charAt(i))) {
                nums++;
            }
            if (nums == k) {
                return k;
            }
            if (nums > max) {
                max = nums;
            }
        }

        return max;
    }

    private boolean isVowel(char c) {
        return (1065233 & (1 << (c - 'a'))) != 0;
    }
}

